
import {Dep} from './Dep'

export class Watcher {
  constructor(vm, key, cd) {
    this.vm = vm
    this.key = key
    this.cd = cd
    Dep.nb = this

    this.oldValue = vm[key]

    Dep.nb = null
    
  }

  update() {
    let newValue = this.vm[this.key]

    if(newValue === this.oldValue) return

    this.cd(newValue)
  }
}